﻿<link href="/Content/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="/Content/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<script src="/Content/js/plugins/iCheck/icheck.min.js"></script>
<script src="/Content/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script src="/Content/layer/layer.js"></script>
<script>


	function sendsim(id) {
		layer.open({
			type: 2,
			title: '发送通知',
			shadeClose: true,
			shade: 0.8,
			area: ['380px', '50%'],
			content: '/index.php/Home/Index/sendtongzhi?tvid=' + id //iframe的url
		});
	}
	function cleartv(id) {
		var json = {};
		json.type = "videotongzhi";
		json.zuid = "0";
		json.tvid = id;
		json.content = "";
		var str = JSON.stringify(json);
		console.log(str);
		socket.emit('broadcast', str);
		layer.msg("发送成功");
	}
	function clearlogo(id) {
		$.post("/index.php/Home/Index/clearlogo", { "id": id }, function (data) {
			if (data == "0") {

				swal("Deleted!", "操作成功", "success");
				window.location.reload();//刷新当前页面.
			} else {
				swal("Deleted!", "系统异常", "success");
			}
		});
	}
</script>
<div class="col-lg-12">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			网络电视
			<span style="float:right">
				<a href="#" onclick="update()">数据更新</a> &nbsp;&nbsp;
				<a href="#" onclick="cleartv(0)">全频道清屏</a> &nbsp;&nbsp;
				<a href="#" onclick="sendsim(0)">全频道通知</a> &nbsp;&nbsp;
				<a href="/index.php/Home/Index/addtv">添加</a></span>
		</div>

		<div class="ibox-content">

			<button id="delete" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top"
				title="Move to trash"><i class="fa fa-trash-o"></i> </button>

			<table class="table table-striped">
				<thead>

					<tr>
						<th>#</th>

						<th>名称</th>
						<th>类型</th>
						<th>LOGO标题</th>
						<th>LOGO图标</th>

						<th>排序</th>
						<th>操作</th>
						<th>会议</th>
					</tr>
				</thead>
				<tbody>
					<volist name="alist" id="vo">
						<tr>
							<td><input type="checkbox" value="{$vo['id']}" class="i-checks" name="input[]"></td>

							<td>{$vo['name']}</td>
							<td>

								<if condition="($vo['typeid'] eq 1)">
									<span>会议直播</span>
									<else />
									<span>网络电视</span>
								</if>
							</td>
							<td>{$vo['logotitle']}</td>

							<td>
								<if condition="($vo['logoimg'] eq '')">
									暂无
									<else />
									<img src="/{$vo['logoimg']}" width="50px;">
								</if>
							</td>

							<td>{$vo['seq']}</td>
							<td><a href="/index.php/Home/Index/addtv?id={$vo['id']}">修改</a>

								&nbsp;
								<a href="#" onclick="sendsim({$vo['id']})">发送通知</a>
								&nbsp;
								<a href="#" onclick="cleartv({$vo['id']})">清屏</a>
								&nbsp;
								<a href="#" onclick="clearlogo({$vo['id']})">清除LOGO</a>
							</td>
							<td>
								<if condition="($vo['typeid'] eq 1) and ($vo['state'] eq 0)">
									<a href="#" class="start" data-id="{$vo['id']}" data-url="{$vo['url']}"
										data-logotitle="{$vo['logotitle']}" data-imgurl="{$vo['logoimg']}"
										data-nosignalimg="{$vo['nosignalimg']}" data-desc="{$vo['desc']}">开始会议</a>
									<elseif condition="($vo['typeid'] eq 1) and ($vo['state'] eq 1)" />
									<a href="#" class="end" data-kaihuizuid="{$vo['kaihuizuid']}" data-id="{$vo['id']}">结束会议</a>
									<else />
								</if>
							</td>

						</tr>
					</volist>
					<tr>
						<td colspan="9">
							<div class="pagelist">{$page}</div>
						</td>
					</tr>
				</tbody>
			</table>

		</div>

		<div class="modal fade" id="editbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" id="myModal">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">开始会议</h4>
					</div>
					<div class="modal-body">
						<fieldset>



							<div class="control-group">
								<label for="input01" class="control-label">选择组</label>
								<div class="controls">
									<select  id="zuid" class="form-control">
										<option value="0">
											全部
										</option>
										<volist name="fenzulist" id="vo">
											<option value='{$vo['id']}'>
												{$vo['zuname']}
											</option>
										</volist>
										
									</select>
								</div>
							</div>



						</fieldset>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary" onclick="kaihuipost()">确认</button>
						</div>
					</div>
				</div>
			</div>
		</div>

	</div>
</div>

<script src="https://cdn.socket.io/socket.io-1.2.1.js"></script>
<script>
	var socket;
	var id,url,logotitle,imgurl,nosignalimg,desc;
	function kaihuipost() {

		var kaihuizuid =$("#zuid").val();
		$.post("/index.php/Home/Index/tvstate", { "id": id, "state": 1,"kaihuizuid":kaihuizuid }, function (data) {
			if (data == "0") {
				kaihui(id, url, logotitle, imgurl, nosignalimg, desc,kaihuizuid);
				swal("Deleted!", "操作成功", "success");
				window.location.reload();//刷新当前页面.
			} else {
				swal("Deleted!", "系统异常", "success");
			}
		});
	}

	$(document).ready(function () {

		initsocket();

		$(".start").click(function () {
			id = $(this).data("id");
		    url = $(this).data("url");
		    imgurl = $(this).data("imgurl");
	    	nosignalimg = $(this).data("nosignalimg");
		    desc = $(this).data("desc");
		    logotitle = $(this).data("logotitle");



			$("#editbox").modal('show');


		});
		$(".end").click(function () {
			var id = $(this).data("id");
			var kaihuizuid = $(this).data("kaihuizuid");
			swal({
				title: "确定要结束会议吗?",
				text: "",
				type: "warning",
				showCancelButton: true,
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "是",
				closeOnConfirm: false
			}, function () {

				$.post("/index.php/Home/Index/tvstate", { "id": id, "state": 0,"kaihuizuid":kaihuizuid }, function (data) {
					if (data == "0") {
						enkaihui(kaihuizuid);
						swal("Deleted!", "操作成功", "success");
						window.location.reload();//刷新当前页面.
					} else {
						swal("Deleted!", "系统异常", "success");
					}
				});
			});
		});
		$('.i-checks').iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
		});

		$("#delete").click(function () {
			var i = 0;
			var ids = "";
			$('.i-checks').each(function () {
				var check = this;

				if (check.checked) {
					i = i + 1;
					ids = ids + $(this).val() + ",";
				}

			});

			if (i == 0) {
				swal({
					title: "请选择",
					text: ""
				});

			} else {
				swal({
					title: "确定要删除吗?",
					text: "",
					type: "warning",
					showCancelButton: true,
					confirmButtonColor: "#DD6B55",
					confirmButtonText: "是",
					closeOnConfirm: false
				}, function () {
					ids = ids.substring(0, ids.length - 1);
					$.post("/index.php/Home/Index/deltv", { "ids": ids }, function (data) {
						if (data == "0") {
							swal("Deleted!", "已删除", "success");
							window.location.reload();//刷新当前页面.
						} else {
							swal("Deleted!", "系统异常", "success");
						}
					});

				});


			}
		});



	});
	function initsocket() {
		socket = io.connect('{$socket}');//与服务器进行连接		
	}

	function kaihui(id, url, logotitle, imgurl, nosignalimg, desc,kaihuizuid) {
		var json = {};
		json.type = "kaihui";
		json.content = url + "|" + imgurl + "|" + nosignalimg + "|" + desc + "|" + logotitle;
		json.zuid = kaihuizuid;
		json.tvid = id;
		var str = JSON.stringify(json);
		console.log(str);
		socket.emit('broadcast', str);
	}

	function enkaihui(kaihuizuid) {
		var json = {};
		json.type = "endkaihui";
		json.content = "";
		json.zuid = kaihuizuid;
		json.tvid = 0;
		var str = JSON.stringify(json);
		console.log(str);
		socket.emit('broadcast', str);
	}
	function update() {
		var json = {};
		json.type = "updatetv";
		json.content = "";
		json.zuid = 0;
		json.tvid = 0;
		var str = JSON.stringify(json);
		console.log(str);
		socket.emit('broadcast', str);
		swal("success!", "更新成功", "success");
	}


</script>